package com.wp.www.controller;

import com.wp.www.entity.CommonResult;
import com.wp.www.service.AccountService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@Slf4j
public class AccountController {

    @Resource
    private AccountService accountService;

    @GetMapping("/account/{userId}/{money}")
    public CommonResult deductAccount(@PathVariable("userId") String userId, @PathVariable("money") BigDecimal money){
        log.info("*****全局事务xid:{}", RootContext.getXID());
        Integer resultRow = accountService.deduct(userId, money);
        return new CommonResult(200,"扣减成功");
    }
}
